﻿
@{
    ViewBag.Title = "会员列表";
}
@section CSS{

}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            会员
            <small>列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">会员管理</a></li>
            <li class="active">用户列表</li>
        </ol>
    </section>
    <section>
        <div class="col-xs-12 ">
            <div class="box box-primary">
                <div class="box-body">
                    <div class="col-md-6 ">
                        <div class="info-box-content">
                            <span class="info-box-number"><small>总用户： </small>@ViewBag.user_total  </span>
                        </div>
                    </div>
                    <div class="col-md-3 ">
                        <div style="text-align:center;">
                            <span class="info-box-number">@ViewBag.user_today </span>
                            <span class="info-box-text" style="color:#c2c1c1;">今日新增用户</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header my_search">
                        <select style="width:120px;" class="form-control" id="status">
                            <option value="-1">-用户状态-</option>
                            <option value="1">正常</option>
                            <option value="0">黑名单</option>
                        </select>
                        <select style="width:120px; display:none" class="form-control" id="grade">
                            <option value="-1">-用户级别-</option>
                            <option value="1">Vip1</option>
                            <option value="0">普通</option>
                        </select>
                        <input type="text" style="width:120px;" class="form-control pull-left" id="UserName" placeholder="用户名">
                        <input type="text" style="width:120px;" class="form-control pull-left" id="UserNo" placeholder="用户编号">
                        <input type="text" style="width:120px;" class="form-control pull-left" id="startTime" placeholder="注册日期-起">
                        <span style="line-height:30px;">至</span>
                        <input type="text" style="width:120px;" class="form-control pull-left" id="endTime" placeholder="注册日期-止">
                        <button type="button" class="btn btn-default " id="btnSearch"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                    <div class="box-body">
                        <table id="DataList" class="table table-bordered table-striped table-hover ">
                            <thead>
                                <tr>
                                    <th>用户编号</th>
                                    <th>用户名</th>
                                    <th>昵称</th>
                                    <th>余额(元)</th>
                                    <th>积分</th>
                                    <th>所属商家</th>
                                    <th>商店名称</th>
                                    <th>商店类型</th>
                                    <th>商店地址</th>
                                    <th>用户状态</th>
                                    <th>添加时间</th>
                                </tr>
                            </thead>
                            <tbody> </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
@section JS{
    <script>
        var _user=@ViewBag.SetRole;
        $(function () {
            //初始化表格
            GenerateTable();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#btnSearch").on("click", function () {
                u_table.fnDestroy();
                GenerateTable();
            });

            $('#startTime').datepicker({
                autoclose: true
            });

            $('#endTime').datepicker({
                autoclose: true
            });
        });
        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": true,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "sScrollX": true,
                "bAutoWidth":false,
                "fnServerParams": function (aoData) {
                    var status = $("#status").val();
                    var grade = $("#grade").val();
                    var datemin = $('#startTime').val();
                    var datemax = $("#endTime").val();
                    var userName = $.trim($("#UserName").val());
                    var userNo = $.trim($("#UserNo").val());
                    aoData.push(
                        { "name": "dateMin", "value": datemin },
                        { "name": "dateMax", "value": datemax },
                        { "name": "userName", "value": userName },
                        { "name": "userNo", "value": userNo },
                        { "name": "grade", "value": grade },
                        { "name": "status", "value": status }
                    );
                },
                "sAjaxSource": "/User/GetUsersByPage",
                "aoColumns": [
                    { "mDataProp": 'id' },
                    { "mDataProp": 'name' },
                    { "mDataProp": 'nick_name' },
                    { "mDataProp": 'balance' },
                    { "mDataProp": 'exp' },
                    { "mDataProp": 'company_name' },
                    { "mDataProp": 'store_name' },
                    { "mDataProp": 'store_type' },
                    { "mDataProp": 'store_area', "mRender": function (data, type, full) {
                            return data+'<br />'+full.store_address;
                        }
                    },
                    {
                        "mDataProp": 'status', "mRender": function (data, type, full) {
                            if (data == 1) {
                                return '<a style="text-decoration:none" class="btn btn-success" onClick="user_noPass(this,' + full.id + ')" href="javascript:;" title="点击加入黑名单">正常</a>';
                            } else {
                                return '<a style="text-decoration:none" class="btn btn-danger" onClick="user_pass(this,' + full.id + ')" href="javascript:;" title="点击解除黑名单">黑名单</a>';
                            }
                        }
                    },
                    {
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD HH:mm:ss");
                        }
                    }
                ]
            });
        }

        /*启用*/
        function user_pass(obj, id) {
            layer.confirm('确定启用？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/user/SetIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("正常").attr("onClick", "user_noPass(this," + id + ")").attr("title", "点击加入黑名单").attr("class", "btn btn-success");
                            layer.msg('已启用', { icon: 6, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
        /*禁用*/
        function user_noPass(obj, id) {
            layer.confirm('确定加入黑名单？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/user/SetIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("黑名单").attr("onClick", "user_pass(this," + id + ")").attr("title", "点击启用").attr("class", "btn btn-danger");
                            layer.msg('已加入黑名单', { icon: 5, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
        /*设为趣卡会员*/
        function user_setVip(obj, id) {
            layer.confirm('确定赠送1年趣卡会员？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/user/SetVip",
                    dataType: "json",
                    data: { id: id, isVip: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).parent().text("是");
                            layer.msg('设置成功', { icon: 6, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
        ///*重置密码*/
        //function user_setPwd(obj, id) {
        //    layer.confirm('确认要将登录密码重置为：123456 ？', function (index) {
        //        $.ajax({
        //            type: "get",
        //            url: "/User/SetPwd/" + id,
        //            dataType: "json",
        //            data: {},
        //            success: function (data) {
        //                if (data.result.status == "y") {
        //                    layer.msg('重置登录密码为123456，请登录后及时修改为安全密码!');
        //                }
        //                else {
        //                    alert(data.result.info);
        //                }
        //            }
        //        });

        //    });
        //}
    </script>
}
